package dao.hibernate;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

/**
 * @author Andre R.F.
 * @since 1.0
 */
public class HibernateUtil {

	private static SessionFactory sessionFactory;

	private static void createSessionFactory() {
		sessionFactory = new AnnotationConfiguration().configure()
				.buildSessionFactory();
	}

	public static Session getSession() {
		return sessionFactory.getCurrentSession();
	}

	public static SessionFactory getSessionFactory() {
		if (sessionFactory == null) {
			createSessionFactory();
		}
		return sessionFactory;
	}

}
